package com.permission.guochaodev

import androidx.fragment.app.FragmentActivity

/**
 *@fileName `object`
 *@date2020/12/3  17:24
 *@author object$
 *@describe TODO
 *@desc 单例
 */
object PermissionX {
        private const val TAG="InvisibleFragment"

        fun request(activity:FragmentActivity,vararg permissions:String,callback:PermissionCallback){
            val fragmentManager=activity.supportFragmentManager
            val existedFragment=fragmentManager.findFragmentByTag(TAG)
            val fragment=if(existedFragment!=null){
                existedFragment as InvisibleFragment
            }else{
                val invisibleFragment=InvisibleFragment()
                fragmentManager.beginTransaction().add(invisibleFragment,TAG).commitNow()
                invisibleFragment
            }
            fragment.requestNow(callback,*permissions)
        }
}